package cn.candy.user.config;

import cn.candy.user.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 配置类：登录拦截器
 */
@Configuration
public class MyWebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
                //登录：放行到登录页面的请求【/login】  和  登录请求【/login/account】
                .excludePathPatterns("/login/**")
                //注册：放行用户注册：/user/register/**
                .excludePathPatterns("/user/register/**")
                //注册：放行店铺入驻
                .excludePathPatterns("/shop/settlement")
                //放行文件上传接口
                .excludePathPatterns("/fastDfs")
                //放行验证码
                .excludePathPatterns("/verifycode/**")
                //放行swagger
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**")
                //放行支付包支付的异步通知
                .excludePathPatterns("/notify");
    }
}
